package engine.network
{
	import game.ui.hud.*;
	import game.ui.core.*;
	
	import engine.core.*;
	
	import flash.utils.ByteArray;
	
	public class RxJiraClient
	{
		private static var s_web:RxWebClient;
		private static var s_projectName:String;
		private static var s_projectKey:String;
		private static var s_collector:Function = null;
		private static var s_initialized:Boolean;
		private static var s_bugPanel:RxBugPanel;
		
		public function RxJiraClient()
		{
		}
		
		public static function ShowUI() : void
		{
			if (!s_initialized)
			{
				return;
			}
			
			if (!s_bugPanel)
			{
				s_bugPanel = new RxBugPanel();
			}
			
			if (!s_bugPanel.parent)
			{
				RxDialogManager.instance.ShowDialog(s_bugPanel, true);
			}
		}
		
		public static function Initialize(name:String, param2:String, param3:String, param4:String, key:String, collector:Function) : void
		{
			if (s_initialized)
			{
				return;
			}
			s_initialized = true;
			s_projectName = name;
			s_projectKey = key.toUpperCase();
			s_collector = collector;
			s_web = new RxWebClient(param2);
			s_web.SetAuthorization(param3, param4);
		}
		
		public static function HideUI() : void
		{
			if (!s_initialized)
			{
				return;
			}
			if (s_bugPanel && s_bugPanel.parent)
			{
				s_bugPanel.RemoveFromLayer();
			}
		}
		
		public static function SubmitBug(param1:String, param2:String) : void
		{
			var _onResponse:Function;
			var summary:* = param1;
			var description:* = param2;
			_onResponse = function (param1:int, param2:ByteArray) : void
			{
				var _loc_3:String = null;
				var _loc_4:Object = null;
				if (param1 == 201)
				{
					_loc_3 = param2.toString();
					_loc_4 = JSON.parse(_loc_3);
					RxLog.Info("Jira Bug " + _loc_4.key + " accepted");
				}
				else
				{
					RxLog.Info("Jira Bug submission failed");
				}
				return;
			};
			var state:String;
			if (s_collector != null)
			{
				state = s_collector();
			}
			description = description + ("\n\n" + state);
			var bug:* = new Object();
			bug.fields = new Object();
			bug.fields.project = new Object();
			bug.fields.project.key = s_projectKey;
			bug.fields.summary = summary;
			bug.fields.description = description;
			bug.fields.issuetype = new Object();
			bug.fields.issuetype.id = 1;
			var json:* = JSON.stringify(bug);
			var payload:* = new ByteArray();
			payload.writeUTFBytes(json);
			s_web.PostData("/rest/api/2/issue/", "application/json", payload, _onResponse);
		}
	}
}